-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add explicit cases to PluralCategory
#5426
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
robertbastian
requested review from
sffc,
Manishearth,
filmil,
zbraniecki,
pdogr,
eggrobin and
nordzilla
as code owners
August 21, 2024 21:56
sffc
requested changes
Aug 22, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make it a separate enum. While it would be much easier and cleaner in the short term to extend the existing enum as you did here, there are several reasons why it is wrong to do so:
- CLDR defines the plural categories as being zero, one, two, few, many, other. Explicit0 and Explicit1 are not part of the definition.
- ECMA-402 likewise defines a plural category as being one of the six.
PluralRules
should never return Explicit0 or Explicit1 as a category. It can match on it, but it should never return it, because it is not the plural category of the number.- Even if you don't believe me on philosophical points 1-3, a technical reason why we shouldn't extend the enum is that the enum is exhaustive. We made a decision in 1.0 that the enum would be exhaustive and we would deprecate it and introduce a new enum if CLDR ever introduced new plural categories. However, with the explicit values, CLDR absolutely can and will add new explicit string values, so the enum definitely cannot be exhaustive.
enum PluralCategoryExtended {
PluralCategory(PluralCategory),
Explicit0,
Explicit1,
}
impl PluralRules {
pub fn select_from_plural_elements<T>(&self, op: PluralOperands, choices: &PluralElements<T>) -> T {
let category = self.category_for(op);
if op.is_exactly_one() {
if let Some(value) = choices.get_explicit1() {
return value;
}
}
// same for zero
choices.get(category)
}
/*
pub fn select_with_explicit(&self, op: PluralOperands) -> (Option<Explicit>, PluralCategory) {
let category = self.category_for(op);
if op.is_exactly_one() {
if let Some(value) = choices.get_explicit1() {
return (Some(Explicit::One), category);
}
}
// same for zero
(None, category)
// ...
}
*/
}
// in icu::plurals
pub struct PluralElements<'a, T: ?Sized> {
pub other: &'a T,
pub zero: Option<&'a T>,
// ...
}
// in icu::plurals::provider
impl PluralElementsV1<T> {
pub fn get(&self, op: PluralOperands, rules: &PluralRules) -> &T {
let category = rules.category_for(op);
if op.is_exactly_zero() {
if let Some(value) = self.get_explicit0() {
return value;
}
}
if op.is_exactly_one() {
if let Some(value) = self.get_explicit1() {
return value;
}
}
self.get(category)
}
pub fn new(builder: PluralElements<T>) -> Self where T: PartialEq {}
}
Decision:
LGTM: @robertbastian @sffc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explicit 0 and 1 cases are required by patterns in multiple components.